//package com.sctvcloud.zhaohua_sd.ui.activities;
//
//import android.os.Bundle;
//import android.support.v7.widget.DefaultItemAnimator;
//import android.support.v7.widget.GridLayoutManager;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.text.TextUtils;
//import android.view.View;
//import android.widget.ImageView;
//import android.widget.LinearLayout;
//import android.widget.Toast;
//
//import com.google.gson.Gson;
//import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
//import com.ruihang.generalibrary.utils.SharedPreferencesUtil;
//import com.sctvcloud.zhaohua_sd.R;
//import com.sctvcloud.zhaohua_sd.application.Cache;
//import com.sctvcloud.zhaohua_sd.base.BaseActivity;
//import com.sctvcloud.zhaohua_sd.beans.CityServiceBean;
//import com.sctvcloud.zhaohua_sd.beans.ServiceCityListVo;
//import com.sctvcloud.zhaohua_sd.beans.ServiceConfigBean;
//import com.sctvcloud.zhaohua_sd.http.AbsNetCallBack;
//import com.sctvcloud.zhaohua_sd.http.NetUtils;
//import com.sctvcloud.zhaohua_sd.ui.adapter.ExchangeCityListAdapter;
//import com.sctvcloud.zhaohua_sd.ui.fragment.ServiceFragment;
//import com.sctvcloud.zhaohua_sd.ui.utils.TitleUtils;
//import com.sctvcloud.zhaohua_sd.ui.utils.UIUtils;
//import com.sctvcloud.zhaohua_sd.ui.widget.SpacesItemDecoration;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import butterknife.BindView;
//import butterknife.ButterKnife;
//import butterknife.internal.Utils;
//
//public class ExchangeCityActivity extends BaseActivity implements ExchangeCityListAdapter.OnItemClickListener {
//
//    public static final String SERVICE_CITY = "service_city";
//    public static final String CITY_URL_KEY = "city_url";
//    private String cityUrl;
//    @BindView(R.id.city_list)
//    protected RecyclerView cityList;
//    @BindView(R.id.title_top_back)
//    protected ImageView backImg;
//    @BindView(R.id.city_name)
//    protected CustomFontTextView currentCity;
//
//    private ExchangeCityListAdapter adapter;
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        new TitleUtils(this).useAndSetTxTitle("切换城市");
//
//        initView();
//        getServiceConfig();
//    }
//
//    @Override
//    protected void initInject() {
//        setContentView(R.layout.activity_exchange_service_city);
//        ButterKnife.bind(this);
//    }
//
//    private void initView() {
//        String cityJson = (String) SharedPreferencesUtil.getParam(this, SERVICE_CITY, "");
//        CityServiceBean bean;
//        String cityName = "";
//        if (!TextUtils.isEmpty(cityJson)) {
//            bean = (CityServiceBean) (new Gson().fromJson(cityJson, CityServiceBean.class));
//            cityName = bean.getCityName();
//            currentCity.setText(cityName);
//        } else {
//            currentCity.setText("成都");
//        }
//        int decoration = 20;
//        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) currentCity.getLayoutParams();
//        params.width = (getResources().getDisplayMetrics().widthPixels - (2 * decoration + UIUtils.dip2px(this, 14) * 2)) / 3;
//        currentCity.setLayoutParams(params);
//
//        cityList.setLayoutManager(new GridLayoutManager(this, 3));
//        cityList.setItemAnimator(new DefaultItemAnimator());
//        cityList.addItemDecoration(new SpacesItemDecoration(decoration));
//        adapter = new ExchangeCityListAdapter(this, null, cityName);
//        adapter.setListener(this);
//        cityList.setAdapter(adapter);
//    }
//
//
//    private void getServiceConfig() {
//        NetUtils.getNetAdapter().getServiceConfigData(getOwnerName(), ServiceFragment.configUrl, new AbsNetCallBack<ServiceConfigBean>(ServiceConfigBean.class) {
//            @Override
//            public void onSuc(ServiceConfigBean config) {
//                if (null != config) {
//                    getServiceCityList(config.getUrl());
//                }
//            }
//
//            @Override
//            public void onEnd() {
//                super.onEnd();
//            }
//
//            @Override
//            public void onError(Throwable ex, String errorMsg) {
//                super.onError(ex, errorMsg);
//                Toast.makeText(ExchangeCityActivity.this,"请求数据错误",Toast.LENGTH_LONG).show();
//            }
//        });
//    }
//    /**
//     * 获取服务模块配置的可用城市列表
//     */
//    public void getServiceCityList(String cityUrl) {
//        NetUtils.getNetAdapter().getServiceCityList(getOwnerName(), cityUrl, new AbsNetCallBack<ServiceCityListVo>(ServiceCityListVo.class) {
//            @Override
//            public void onSuc(ServiceCityListVo vo) {
//                if (null != vo.getListInfo()) {
//                    Cache.getInstance().setServiceCityList(vo.getListInfo());
//                    adapter.setData(vo.getListInfo());
//                    adapter.notifyDataSetChanged();
//                }
//            }
//
//            @Override
//            public void onEnd() {
//                super.onEnd();
//            }
//
//            @Override
//            public void onError(Throwable ex, String errorMsg) {
//                super.onError(ex, errorMsg);
//                if(!TextUtils.isEmpty(errorMsg)) {
//                    Toast.makeText(ExchangeCityActivity.this, errorMsg, Toast.LENGTH_LONG).show();
//                }else{
//                    Toast.makeText(ExchangeCityActivity.this,"请求数据错误",Toast.LENGTH_LONG).show();
//                }
//            }
//        });
//    }
//
//    @Override
//    public void onCityItemClick(CityServiceBean cityState) {
//        String cityJson = new Gson().toJson(cityState);
//        SharedPreferencesUtil.setParam(this, SERVICE_CITY, cityJson);
//        setResult(RESULT_OK);
//        this.finish();
//    }
//}
